package cn.hejiang.quartz.jobs;

import cn.hejiang.order.service.IAdoptOrderService;
import cn.hejiang.quartz.constans.JobTypes;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

// Quartz工具动态创建的
public class MainJob implements Job {

    @Autowired
    private IAdoptOrderService adoptOrderService;

    /**
     * 超时支付或确认时间之后，直接被定时器触发执行
     * @param jobExecutionContext
     * @throws JobExecutionException
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        Map<String, Object> params = (Map<String, Object>) jobDataMap.get("params");
        String type = (String) params.get("type"); // 根据不同的type执行不同的业务
        switch (type) {
            case JobTypes.PAY_OVER_TIME_ADOPT_ORDER:
                Long orderId = (Long) params.get("orderId");
                adoptOrderService.deleteByQuartz(orderId);
                break;
            default:
                break;
        }

    }
}
